<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>mainwindow.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-widgets-icons-example.html">Icons Example</a></td><td >mainwindow.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">mainwindow.cpp 示例文件</h1>
<span class="subtitle">widgets/icons/mainwindow.cpp</span>
<!-- $$$widgets/icons/mainwindow.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>

  <span class="preprocessor">#include &quot;iconpreviewarea.h&quot;</span>
  <span class="preprocessor">#include &quot;iconsizespinbox.h&quot;</span>
  <span class="preprocessor">#include &quot;imagedelegate.h&quot;</span>
  <span class="preprocessor">#include &quot;mainwindow.h&quot;</span>

  <span class="keyword">enum</span> { OtherSize <span class="operator">=</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_CustomBase };

  MainWindow<span class="operator">::</span>MainWindow()
  {
      <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>centralWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>(<span class="keyword">this</span>);
      setCentralWidget(centralWidget);

      createActions();

      <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(centralWidget);

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>previewGroupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Preview&quot;</span>));
      previewArea <span class="operator">=</span> <span class="keyword">new</span> IconPreviewArea(previewGroupBox);
      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>previewLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(previewGroupBox);
      previewLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(previewArea);

      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(previewGroupBox<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(createImagesGroupBox()<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>vBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
      vBox<span class="operator">-</span><span class="operator">&gt;</span>addWidget(createIconSizeGroupBox());
      vBox<span class="operator">-</span><span class="operator">&gt;</span>addWidget(createHighDpiIconSizeGroupBox());
      vBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(<span class="keyword">new</span> <span class="type"><a href="qspaceritem.html">QSpacerItem</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Ignored<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>MinimumExpanding));
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(vBox<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      createContextMenu();

      setWindowTitle(tr(<span class="string">&quot;Icons&quot;</span>));
      checkCurrentStyle();
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>button(OtherSize)<span class="operator">-</span><span class="operator">&gt;</span>click();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>show()
  {
      <span class="type"><a href="qmainwindow.html">QMainWindow</a></span><span class="operator">::</span>show();
      connect(windowHandle()<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="../qtgui/qwindow.html">QWindow</a></span><span class="operator">::</span>screenChanged<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>screenChanged);
      screenChanged();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>about()
  {
      <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>about(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">&quot;About Icons&quot;</span>)<span class="operator">,</span>
              tr(<span class="string">&quot;The &lt;b&gt;Icons&lt;/b&gt; example illustrates how Qt renders an icon in &quot;</span>
                 <span class="string">&quot;different modes (active, normal, disabled, and selected) and &quot;</span>
                 <span class="string">&quot;states (on and off) based on a set of images.&quot;</span>));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>changeStyle(bool checked)
  {
      <span class="keyword">if</span> (<span class="operator">!</span>checked)
          <span class="keyword">return</span>;

      <span class="keyword">const</span> <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>action <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(sender());
      <span class="type"><a href="qstyle.html">QStyle</a></span> <span class="operator">*</span>style <span class="operator">=</span> <span class="type"><a href="qstylefactory.html">QStyleFactory</a></span><span class="operator">::</span>create(action<span class="operator">-</span><span class="operator">&gt;</span>data()<span class="operator">.</span>toString());
      Q_ASSERT(style);
      <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>setStyle(style);

      foreach (<span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span> <span class="operator">*</span>button<span class="operator">,</span> sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>buttons()) {
          <span class="keyword">const</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PixelMetric metric <span class="operator">=</span> <span class="keyword">static_cast</span><span class="operator">&lt;</span><span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PixelMetric<span class="operator">&gt;</span>(sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>id(button));
          <span class="keyword">const</span> <span class="type">int</span> value <span class="operator">=</span> style<span class="operator">-</span><span class="operator">&gt;</span>pixelMetric(metric);
          <span class="keyword">switch</span> (metric) {
          <span class="keyword">case</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_SmallIconSize:
              button<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Small (%1 x %1)&quot;</span>)<span class="operator">.</span>arg(value));
              <span class="keyword">break</span>;
          <span class="keyword">case</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_LargeIconSize:
              button<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Large (%1 x %1)&quot;</span>)<span class="operator">.</span>arg(value));
              <span class="keyword">break</span>;
          <span class="keyword">case</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_ToolBarIconSize:
              button<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Toolbars (%1 x %1)&quot;</span>)<span class="operator">.</span>arg(value));
              <span class="keyword">break</span>;
          <span class="keyword">case</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_ListViewIconSize:
              button<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;List views (%1 x %1)&quot;</span>)<span class="operator">.</span>arg(value));
              <span class="keyword">break</span>;
          <span class="keyword">case</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_IconViewIconSize:
              button<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Icon views (%1 x %1)&quot;</span>)<span class="operator">.</span>arg(value));
              <span class="keyword">break</span>;
          <span class="keyword">case</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_TabBarIconSize:
              button<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Tab bars (%1 x %1)&quot;</span>)<span class="operator">.</span>arg(value));
              <span class="keyword">break</span>;
          <span class="keyword">default</span>:
              <span class="keyword">break</span>;
          }
      }

      triggerChangeSize();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>changeSize(<span class="type">int</span> id<span class="operator">,</span> bool checked)
  {
      <span class="keyword">if</span> (<span class="operator">!</span>checked)
          <span class="keyword">return</span>;

      <span class="keyword">const</span> bool other <span class="operator">=</span> id <span class="operator">=</span><span class="operator">=</span> <span class="type">int</span>(OtherSize);
      <span class="keyword">const</span> <span class="type">int</span> extent <span class="operator">=</span> other
          <span class="operator">?</span> otherSpinBox<span class="operator">-</span><span class="operator">&gt;</span>value()
          : <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>style()<span class="operator">-</span><span class="operator">&gt;</span>pixelMetric(<span class="keyword">static_cast</span><span class="operator">&lt;</span><span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PixelMetric<span class="operator">&gt;</span>(id));

      previewArea<span class="operator">-</span><span class="operator">&gt;</span>setSize(<span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(extent<span class="operator">,</span> extent));
      otherSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(other);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>triggerChangeSize()
  {
      changeSize(sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>checkedId()<span class="operator">,</span> <span class="keyword">true</span>);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>changeIcon()
  {
      <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> icon;

      <span class="keyword">for</span> (<span class="type">int</span> row <span class="operator">=</span> <span class="number">0</span>; row <span class="operator">&lt;</span> imagesTable<span class="operator">-</span><span class="operator">&gt;</span>rowCount(); <span class="operator">+</span><span class="operator">+</span>row) {
          <span class="keyword">const</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>fileItem <span class="operator">=</span> imagesTable<span class="operator">-</span><span class="operator">&gt;</span>item(row<span class="operator">,</span> <span class="number">0</span>);
          <span class="keyword">const</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>modeItem <span class="operator">=</span> imagesTable<span class="operator">-</span><span class="operator">&gt;</span>item(row<span class="operator">,</span> <span class="number">1</span>);
          <span class="keyword">const</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>stateItem <span class="operator">=</span> imagesTable<span class="operator">-</span><span class="operator">&gt;</span>item(row<span class="operator">,</span> <span class="number">2</span>);

          <span class="keyword">if</span> (fileItem<span class="operator">-</span><span class="operator">&gt;</span>checkState() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Checked) {
              <span class="keyword">const</span> <span class="type">int</span> modeIndex <span class="operator">=</span> IconPreviewArea<span class="operator">::</span>iconModeNames()<span class="operator">.</span>indexOf(modeItem<span class="operator">-</span><span class="operator">&gt;</span>text());
              Q_ASSERT(modeIndex <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">0</span>);
              <span class="keyword">const</span> <span class="type">int</span> stateIndex <span class="operator">=</span> IconPreviewArea<span class="operator">::</span>iconStateNames()<span class="operator">.</span>indexOf(stateItem<span class="operator">-</span><span class="operator">&gt;</span>text());
              Q_ASSERT(stateIndex <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">0</span>);
              <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>Mode mode <span class="operator">=</span> IconPreviewArea<span class="operator">::</span>iconModes()<span class="operator">.</span>at(modeIndex);
              <span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>State state <span class="operator">=</span> IconPreviewArea<span class="operator">::</span>iconStates()<span class="operator">.</span>at(stateIndex);

              <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> fileItem<span class="operator">-</span><span class="operator">&gt;</span>data(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>UserRole)<span class="operator">.</span>toString();
              <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> image(fileName);
              <span class="keyword">if</span> (<span class="operator">!</span>image<span class="operator">.</span>isNull())
                  icon<span class="operator">.</span>addPixmap(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span><span class="operator">::</span>fromImage(image)<span class="operator">,</span> mode<span class="operator">,</span> state);
          }
      }

      previewArea<span class="operator">-</span><span class="operator">&gt;</span>setIcon(icon);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>addSampleImages()
  {
      addImages(QLatin1String(SRCDIR) <span class="operator">+</span> QLatin1String(<span class="string">&quot;/images&quot;</span>));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>addOtherImages()
  {
      <span class="keyword">static</span> bool firstInvocation <span class="operator">=</span> <span class="keyword">true</span>;
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> directory;
      <span class="keyword">if</span> (firstInvocation) {
          firstInvocation <span class="operator">=</span> <span class="keyword">false</span>;
          directory <span class="operator">=</span> <span class="type"><a href="../qtcore/qstandardpaths.html">QStandardPaths</a></span><span class="operator">::</span>standardLocations(<span class="type"><a href="../qtcore/qstandardpaths.html">QStandardPaths</a></span><span class="operator">::</span>PicturesLocation)<span class="operator">.</span>value(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span>());
      }
      addImages(directory);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>addImages(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>directory)
  {
      <span class="type"><a href="qfiledialog.html">QFileDialog</a></span> fileDialog(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">&quot;Open Images&quot;</span>)<span class="operator">,</span> directory);
      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> mimeTypeFilters;
      foreach (<span class="keyword">const</span> <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> <span class="operator">&amp;</span>mimeTypeName<span class="operator">,</span> <span class="type"><a href="../qtgui/qimagereader.html">QImageReader</a></span><span class="operator">::</span>supportedMimeTypes())
          mimeTypeFilters<span class="operator">.</span>append(mimeTypeName);
      mimeTypeFilters<span class="operator">.</span>sort();
      fileDialog<span class="operator">.</span>setMimeTypeFilters(mimeTypeFilters);
      fileDialog<span class="operator">.</span>selectMimeTypeFilter(QLatin1String(<span class="string">&quot;image/png&quot;</span>));
      fileDialog<span class="operator">.</span>setAcceptMode(<span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>AcceptOpen);
      fileDialog<span class="operator">.</span>setFileMode(<span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>ExistingFiles);
      <span class="keyword">if</span> (<span class="operator">!</span>nativeFileDialogAct<span class="operator">-</span><span class="operator">&gt;</span>isChecked())
          fileDialog<span class="operator">.</span>setOption(<span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>DontUseNativeDialog);
      <span class="keyword">if</span> (fileDialog<span class="operator">.</span>exec() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qdialog.html">QDialog</a></span><span class="operator">::</span>Accepted)
          loadImages(fileDialog<span class="operator">.</span>selectedFiles());
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>loadImages(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> <span class="operator">&amp;</span>fileNames)
  {
      foreach (<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fileName<span class="operator">,</span> fileNames) {
          <span class="keyword">const</span> <span class="type">int</span> row <span class="operator">=</span> imagesTable<span class="operator">-</span><span class="operator">&gt;</span>rowCount();
          imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setRowCount(row <span class="operator">+</span> <span class="number">1</span>);
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span> fileInfo(fileName);
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> imageName <span class="operator">=</span> fileInfo<span class="operator">.</span>baseName();
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName2x <span class="operator">=</span> fileInfo<span class="operator">.</span>absolutePath()
              <span class="operator">+</span> QLatin1Char(<span class="char">'/'</span>) <span class="operator">+</span> imageName <span class="operator">+</span> QLatin1String(<span class="string">&quot;@2x.&quot;</span>) <span class="operator">+</span> fileInfo<span class="operator">.</span>suffix();
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span> fileInfo2x(fileName2x);
          <span class="keyword">const</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> image(fileName);
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> toolTip <span class="operator">=</span>
              tr(<span class="string">&quot;Directory: %1\nFile: %2\nFile@2x: %3\nSize: %4x%5&quot;</span>)
                 <span class="operator">.</span>arg(<span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(fileInfo<span class="operator">.</span>absolutePath())<span class="operator">,</span> fileInfo<span class="operator">.</span>fileName())
                 <span class="operator">.</span>arg(fileInfo2x<span class="operator">.</span>exists() <span class="operator">?</span> fileInfo2x<span class="operator">.</span>fileName() : tr(<span class="string">&quot;&lt;None&gt;&quot;</span>))
                 <span class="operator">.</span>arg(image<span class="operator">.</span>width())<span class="operator">.</span>arg(image<span class="operator">.</span>height());
          <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>fileItem <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span>(imageName);
          fileItem<span class="operator">-</span><span class="operator">&gt;</span>setData(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>UserRole<span class="operator">,</span> fileName);
          fileItem<span class="operator">-</span><span class="operator">&gt;</span>setIcon(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span><span class="operator">::</span>fromImage(image));
          fileItem<span class="operator">-</span><span class="operator">&gt;</span>setFlags((fileItem<span class="operator">-</span><span class="operator">&gt;</span>flags() <span class="operator">|</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ItemIsUserCheckable) <span class="operator">&amp;</span> <span class="operator">~</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ItemIsEditable);
          fileItem<span class="operator">-</span><span class="operator">&gt;</span>setToolTip(toolTip);

          <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>Mode mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>Normal;
          <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>State state <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>Off;
          <span class="keyword">if</span> (guessModeStateAct<span class="operator">-</span><span class="operator">&gt;</span>isChecked()) {
              <span class="keyword">if</span> (imageName<span class="operator">.</span>contains(QLatin1String(<span class="string">&quot;_act&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CaseInsensitive))
                  mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>Active;
              <span class="keyword">else</span> <span class="keyword">if</span> (imageName<span class="operator">.</span>contains(QLatin1String(<span class="string">&quot;_dis&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CaseInsensitive))
                  mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>Disabled;
              <span class="keyword">else</span> <span class="keyword">if</span> (imageName<span class="operator">.</span>contains(QLatin1String(<span class="string">&quot;_sel&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CaseInsensitive))
                  mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>Selected;

              <span class="keyword">if</span> (imageName<span class="operator">.</span>contains(QLatin1String(<span class="string">&quot;_on&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CaseInsensitive))
                  state <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>On;
          }

          imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setItem(row<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> fileItem);
          <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>modeItem <span class="operator">=</span>
              <span class="keyword">new</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span>(IconPreviewArea<span class="operator">::</span>iconModeNames()<span class="operator">.</span>at(IconPreviewArea<span class="operator">::</span>iconModes()<span class="operator">.</span>indexOf(mode)));
          modeItem<span class="operator">-</span><span class="operator">&gt;</span>setToolTip(toolTip);
          imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setItem(row<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> modeItem);
          <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span> <span class="operator">*</span>stateItem <span class="operator">=</span>
              <span class="keyword">new</span> <span class="type"><a href="qtablewidgetitem.html">QTableWidgetItem</a></span>(IconPreviewArea<span class="operator">::</span>iconStateNames()<span class="operator">.</span>at(IconPreviewArea<span class="operator">::</span>iconStates()<span class="operator">.</span>indexOf(state)));
          stateItem<span class="operator">-</span><span class="operator">&gt;</span>setToolTip(toolTip);
          imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setItem(row<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> stateItem);
          imagesTable<span class="operator">-</span><span class="operator">&gt;</span>openPersistentEditor(modeItem);
          imagesTable<span class="operator">-</span><span class="operator">&gt;</span>openPersistentEditor(stateItem);

          fileItem<span class="operator">-</span><span class="operator">&gt;</span>setCheckState(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Checked);
      }
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>useHighDpiPixmapsChanged(<span class="type">int</span> checkState)
  {
      <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>setAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AA_UseHighDpiPixmaps<span class="operator">,</span> checkState <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Checked);
      changeIcon();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>removeAllImages()
  {
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setRowCount(<span class="number">0</span>);
      changeIcon();
  }

  <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>MainWindow<span class="operator">::</span>createImagesGroupBox()
  {
      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>imagesGroupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Images&quot;</span>));

      imagesTable <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtablewidget.html">QTableWidget</a></span>;
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setSelectionMode(<span class="type"><a href="qabstractitemview.html">QAbstractItemView</a></span><span class="operator">::</span>NoSelection);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setItemDelegate(<span class="keyword">new</span> ImageDelegate(<span class="keyword">this</span>));

      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> labels;
      labels <span class="operator">&lt;</span><span class="operator">&lt;</span> tr(<span class="string">&quot;Image&quot;</span>) <span class="operator">&lt;</span><span class="operator">&lt;</span> tr(<span class="string">&quot;Mode&quot;</span>) <span class="operator">&lt;</span><span class="operator">&lt;</span> tr(<span class="string">&quot;State&quot;</span>);

      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>horizontalHeader()<span class="operator">-</span><span class="operator">&gt;</span>setDefaultSectionSize(<span class="number">90</span>);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setColumnCount(<span class="number">3</span>);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setHorizontalHeaderLabels(labels);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>horizontalHeader()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qheaderview.html">QHeaderView</a></span><span class="operator">::</span>Stretch);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>horizontalHeader()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="qheaderview.html">QHeaderView</a></span><span class="operator">::</span>Fixed);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>horizontalHeader()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="number">2</span><span class="operator">,</span> <span class="type"><a href="qheaderview.html">QHeaderView</a></span><span class="operator">::</span>Fixed);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>verticalHeader()<span class="operator">-</span><span class="operator">&gt;</span>hide();

      connect(imagesTable<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qtablewidget.html">QTableWidget</a></span><span class="operator">::</span>itemChanged<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>changeIcon);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(imagesGroupBox);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(imagesTable);
      <span class="keyword">return</span> imagesGroupBox;
  }

  <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>MainWindow<span class="operator">::</span>createIconSizeGroupBox()
  {
      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>iconSizeGroupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;Icon Size&quot;</span>));

      sizeButtonGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qbuttongroup.html">QButtonGroup</a></span>(<span class="keyword">this</span>);
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>setExclusive(<span class="keyword">true</span>);

      connect(sizeButtonGroup<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">,</span> bool<span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qbuttongroup.html">QButtonGroup</a></span><span class="operator">::</span>buttonToggled)<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>changeSize);

      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>smallRadioButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>;
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(smallRadioButton<span class="operator">,</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_SmallIconSize);
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>largeRadioButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>;
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(largeRadioButton<span class="operator">,</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_LargeIconSize);
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>toolBarRadioButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>;
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(toolBarRadioButton<span class="operator">,</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_ToolBarIconSize);
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>listViewRadioButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>;
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(listViewRadioButton<span class="operator">,</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_ListViewIconSize);
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>iconViewRadioButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>;
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(iconViewRadioButton<span class="operator">,</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_IconViewIconSize);
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>tabBarRadioButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>;
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(tabBarRadioButton<span class="operator">,</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_TabBarIconSize);
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>otherRadioButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Other:&quot;</span>));
      sizeButtonGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(otherRadioButton<span class="operator">,</span> OtherSize);
      otherSpinBox <span class="operator">=</span> <span class="keyword">new</span> IconSizeSpinBox;
      otherSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">8</span><span class="operator">,</span> <span class="number">256</span>);
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> spinBoxToolTip <span class="operator">=</span>
          tr(<span class="string">&quot;Enter a custom size within %1..%2&quot;</span>)
             <span class="operator">.</span>arg(otherSpinBox<span class="operator">-</span><span class="operator">&gt;</span>minimum())<span class="operator">.</span>arg(otherSpinBox<span class="operator">-</span><span class="operator">&gt;</span>maximum());
      otherSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">64</span>);
      otherSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setToolTip(spinBoxToolTip);
      otherRadioButton<span class="operator">-</span><span class="operator">&gt;</span>setToolTip(spinBoxToolTip);

      connect(otherSpinBox<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qspinbox.html">QSpinBox</a></span><span class="operator">::</span>valueChanged)<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>triggerChangeSize);

      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>otherSizeLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
      otherSizeLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(otherRadioButton);
      otherSizeLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(otherSpinBox);
      otherSizeLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch();

      <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(iconSizeGroupBox);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(smallRadioButton<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(largeRadioButton<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(toolBarRadioButton<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(listViewRadioButton<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(iconViewRadioButton<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(tabBarRadioButton<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(otherSizeLayout<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>setRowStretch(<span class="number">4</span><span class="operator">,</span> <span class="number">1</span>);
      <span class="keyword">return</span> iconSizeGroupBox;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>screenChanged()
  {
      devicePixelRatioLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(<span class="type"><a href="../qtcore/qstring.html">QString</a></span><span class="operator">::</span>number(devicePixelRatioF()));
      <span class="keyword">if</span> (<span class="keyword">const</span> <span class="type"><a href="../qtgui/qwindow.html">QWindow</a></span> <span class="operator">*</span>window <span class="operator">=</span> windowHandle()) {
          <span class="keyword">const</span> <span class="type"><a href="../qtgui/qscreen.html">QScreen</a></span> <span class="operator">*</span>screen <span class="operator">=</span> window<span class="operator">-</span><span class="operator">&gt;</span>screen();
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> screenDescription <span class="operator">=</span>
              tr(<span class="string">&quot;\&quot;%1\&quot; (%2x%3)&quot;</span>)<span class="operator">.</span>arg(screen<span class="operator">-</span><span class="operator">&gt;</span>name())
                 <span class="operator">.</span>arg(screen<span class="operator">-</span><span class="operator">&gt;</span>geometry()<span class="operator">.</span>width())<span class="operator">.</span>arg(screen<span class="operator">-</span><span class="operator">&gt;</span>geometry()<span class="operator">.</span>height());
          screenNameLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(screenDescription);
      }
      changeIcon();
  }

  <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>MainWindow<span class="operator">::</span>createHighDpiIconSizeGroupBox()
  {
      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>highDpiGroupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(tr(<span class="string">&quot;High DPI Scaling&quot;</span>));
      <span class="type"><a href="qformlayout.html">QFormLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qformlayout.html">QFormLayout</a></span>(highDpiGroupBox);
      devicePixelRatioLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(highDpiGroupBox);
      screenNameLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(highDpiGroupBox);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addRow(tr(<span class="string">&quot;Screen:&quot;</span>)<span class="operator">,</span> screenNameLabel);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addRow(tr(<span class="string">&quot;Device pixel ratio:&quot;</span>)<span class="operator">,</span> devicePixelRatioLabel);
      <span class="type"><a href="qcheckbox.html">QCheckBox</a></span> <span class="operator">*</span>highDpiPixmapsCheckBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcheckbox.html">QCheckBox</a></span>(QLatin1String(<span class="string">&quot;Qt::AA_UseHighDpiPixmaps&quot;</span>));
      highDpiPixmapsCheckBox<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>testAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AA_UseHighDpiPixmaps));
      connect(highDpiPixmapsCheckBox<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qcheckbox.html">QCheckBox</a></span><span class="operator">::</span>stateChanged<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>useHighDpiPixmapsChanged);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addRow(highDpiPixmapsCheckBox);
      <span class="keyword">return</span> highDpiGroupBox;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>createActions()
  {
      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>fileMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;File&quot;</span>));

      addSampleImagesAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;Add &amp;Sample Images...&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      addSampleImagesAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcut(tr(<span class="string">&quot;Ctrl+A&quot;</span>));
      connect(addSampleImagesAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>addSampleImages);
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(addSampleImagesAct);

      addOtherImagesAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;&amp;Add Images...&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      addOtherImagesAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcut(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Open);
      connect(addOtherImagesAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>addOtherImages);
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(addOtherImagesAct);

      removeAllImagesAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;&amp;Remove All Images&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      removeAllImagesAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcut(tr(<span class="string">&quot;Ctrl+R&quot;</span>));
      connect(removeAllImagesAct<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>removeAllImages);
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(removeAllImagesAct);

      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addSeparator();

      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>exitAct <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;&amp;Quit&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">::</span>close);
      exitAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Quit);

      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>viewMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;View&quot;</span>));

      styleActionGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qactiongroup.html">QActionGroup</a></span>(<span class="keyword">this</span>);
      foreach (<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>styleName<span class="operator">,</span> <span class="type"><a href="qstylefactory.html">QStyleFactory</a></span><span class="operator">::</span>keys()) {
          <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>action <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;%1 Style&quot;</span>)<span class="operator">.</span>arg(styleName)<span class="operator">,</span> styleActionGroup);
          action<span class="operator">-</span><span class="operator">&gt;</span>setData(styleName);
          action<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
          connect(action<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qaction.html">QAction</a></span><span class="operator">::</span>triggered<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>changeStyle);
          viewMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(action);
      }

      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>settingsMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;Settings&quot;</span>));

      guessModeStateAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;&amp;Guess Image Mode/State&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      guessModeStateAct<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      guessModeStateAct<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">true</span>);
      settingsMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(guessModeStateAct);

      nativeFileDialogAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;&amp;Use Native File Dialog&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      nativeFileDialogAct<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      nativeFileDialogAct<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">true</span>);
      settingsMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(nativeFileDialogAct);

      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>helpMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;Help&quot;</span>));
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;&amp;About&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>about);
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;About &amp;Qt&quot;</span>)<span class="operator">,</span> <a href="qapplication.html#qApp">qApp</a><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>aboutQt);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>createContextMenu()
  {
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>setContextMenuPolicy(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ActionsContextMenu);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>addAction(addSampleImagesAct);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>addAction(addOtherImagesAct);
      imagesTable<span class="operator">-</span><span class="operator">&gt;</span>addAction(removeAllImagesAct);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>checkCurrentStyle()
  {
      foreach (<span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>action<span class="operator">,</span> styleActionGroup<span class="operator">-</span><span class="operator">&gt;</span>actions()) {
          <span class="type"><a href="../qtcore/qstring.html">QString</a></span> styleName <span class="operator">=</span> action<span class="operator">-</span><span class="operator">&gt;</span>data()<span class="operator">.</span>toString();
          <span class="type"><a href="../qtcore/qscopedpointer.html">QScopedPointer</a></span><span class="operator">&lt;</span><span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">&gt;</span> candidate(<span class="type"><a href="qstylefactory.html">QStyleFactory</a></span><span class="operator">::</span>create(styleName));
          Q_ASSERT(<span class="operator">!</span>candidate<span class="operator">.</span>isNull());
          <span class="keyword">if</span> (candidate<span class="operator">-</span><span class="operator">&gt;</span>metaObject()<span class="operator">-</span><span class="operator">&gt;</span>className()
                  <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>style()<span class="operator">-</span><span class="operator">&gt;</span>metaObject()<span class="operator">-</span><span class="operator">&gt;</span>className()) {
              action<span class="operator">-</span><span class="operator">&gt;</span>trigger();
              <span class="keyword">return</span>;
          }
      }
  }

</pre>
</div>
<!-- @@@widgets/icons/mainwindow.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
